<?php
class My_API_sm00_Users
{
    private $_config;

    public function __construct($gameId = null)
    {
        if(!isset($gameId) || !file_exists(CONFIG_PATH2 . "/$gameId.ini")){
            return false;
        }
        
        $config = new Zend_Config_Ini(CONFIG_PATH2 . "/$gameId.ini",APPLICATION_ENV);
        $this->_config = $config;
    }
    
    public function getUsersByServerId($listUser, $serverId){
        $i = 0;
		$infoUsers = array();
        $serverIdPartner = strtolower($serverId);
        
		$userCheck = array_chunk($listUser, 50);
        
		foreach ($userCheck as $key => $listCheck){				
			//get qid of listuser		
			$users 		= str_replace("'", "", implode(",", $listCheck));
			$urlGetQid 	= $this->_config->getUserInfo->url . "?serverID={$serverIdPartner}&accountName={$users}"; 				
			$result 		= json_decode(file_get_contents($urlGetQid));
            //pr($result);
			if(isset($result->status)&& $result->status == 1){
			 
                foreach($result->result[0] as $key=>$row){
                    
                    foreach($row as $r){
    					$infoUsers[$i]['account'] = $key;	
    					$infoUsers[$i]['roleName'] = $r->roleName;
    					if(isset($this->_config->statistics->role))
                        {
                            $title=$this->_config->statistics->role->toArray();
                            foreach($title as $keyTitle => $valTitle)
                            {
                                if(isset($r->$keyTitle))
                                {
                                    $infoUsers[$i][$keyTitle] = $r->$keyTitle;
                                }
                            }
                        }
    					$infoUsers[$i]['serverId'] = $serverId;
    					$i++;
                    }
                }
			}else{
				continue;
			}
		}
        
		return $infoUsers;
    }
}